﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MainView
{
    public partial class SelectForm : Form
    {
        // 记录各窗体初始化的位置
        Point mainLocation = new Point(-5760,-3240);
        Point upLocation = new Point(-1920, -3240);
        Point upcenterLocation = new Point(-1920, -2160);
        Point downcenterLocation = new Point(-1920, -1080);
        Point downLocation = new Point(-1920, 0);

        //各窗体实例化
        Form listForm = new MainForm();
        Form envForm = new PLC.Form1();
        Form tempForm = new TempCtr.MainFrom();        
        Form operForm = new OperationForm();
        Form erpForm = new ErpWeb();

        //定义各状态颜色
        Color onStart =Color.FromArgb(0, 192, 192);
        Color onClose =Color.Gray;
        Color onMain = Color.FromArgb(255, 128, 128);


        public SelectForm()
        {
            InitializeComponent();
        }
        
        private void SelectForm_Load(object sender, EventArgs e)
        {
            //显示各窗体
            operForm.Show();
            listForm.Show();
            tempForm.Show();
            envForm.Show();         
            erpForm.Show();

            //修改各窗体的位置
            listForm.Location = mainLocation;
            envForm.Location = upLocation;
            tempForm.Location = upcenterLocation;
            operForm.Location = downcenterLocation;
            erpForm.Location = downLocation;
        }

        
        //鼠标点击环境软件的按钮
        private void btnEnv_MouseUp(object sender, MouseEventArgs e)
        {
            FormMin();//将窗体缩小，因为窗体最大化时，窗体不能被移动。
            Point tempLocation = envForm.Location;//记录之前窗体的位置
            if (e.Button == MouseButtons.Right)//选中env软件
            {
                if (btnEnv.BackColor == onStart)
                {
                    if (btnTemp.BackColor == onMain)
                    {
                        btnTemp.BackColor = onStart;
                        tempForm.Location = tempLocation;
                    }
                    else if (btnList.BackColor == onMain)
                    {
                        btnList.BackColor = onStart;
                        listForm.Location = tempLocation;
                    }
                    else if (btnOper.BackColor == onMain)
                    {
                        btnOper.BackColor = onStart;
                        operForm.Location = tempLocation;
                    }
                    else if (btnErp.BackColor == onMain)
                    {
                        btnErp.BackColor = onStart;
                        erpForm.Location = tempLocation;
                    }
                    btnEnv.BackColor = onMain;
                    envForm.Location = mainLocation;
                    FormMax();//最大化窗体
                }

            }
        }

        private void btnTemp_MouseUp(object sender, MouseEventArgs e)
        {
            FormMin();
            Point tempLocation = tempForm.Location;
            if (e.Button == MouseButtons.Right)//选中env软件
            {
                if (btnTemp.BackColor == onStart)
                {
                    if (btnEnv.BackColor == onMain)
                    {
                        btnEnv.BackColor = onStart;
                        envForm.Location = tempLocation;
                    }
                    else if (btnList.BackColor == onMain)
                    {
                        btnList.BackColor = onStart;
                        listForm.Location = tempLocation;
                    }
                    else if (btnOper.BackColor == onMain)
                    {
                        btnOper.BackColor = onStart;
                        operForm.Location = tempLocation;
                    }
                    else if (btnErp.BackColor == onMain)
                    {
                        btnErp.BackColor = onStart;
                        erpForm.Location = tempLocation;
                    }
                    btnTemp.BackColor = onMain;
                    tempForm.Location = mainLocation;
                    FormMax();
                }

            }
        }

        private void btnList_MouseUp(object sender, MouseEventArgs e)
        {
            FormMin();
            Point tempLocation = listForm.Location;
            if (e.Button == MouseButtons.Right)//选中env软件
            {
                if (btnList.BackColor == onStart)
                {
                    if (btnEnv.BackColor == onMain)
                    {
                        btnEnv.BackColor = onStart;
                        envForm.Location = tempLocation;
                    }
                    else if (btnTemp.BackColor == onMain)
                    {
                        btnTemp.BackColor = onStart;
                        tempForm.Location = tempLocation;
                    }
                    else if (btnOper.BackColor == onMain)
                    {
                        btnOper.BackColor = onStart;
                        operForm.Location = tempLocation;
                    }
                    else if (btnErp.BackColor == onMain)
                    {
                        btnErp.BackColor = onStart;
                        erpForm.Location = tempLocation;
                    }
                    btnList.BackColor = onMain;
                    listForm.Location = mainLocation;
                    FormMax();
                }

            }

        }

        private void btnOper_MouseUp(object sender, MouseEventArgs e)
        {
            FormMin();
            Point tempLocation = operForm.Location;
            if (e.Button == MouseButtons.Right)//选中env软件
            {
                if (btnOper.BackColor == onStart)
                {
                    if (btnEnv.BackColor == onMain)
                    {
                        btnEnv.BackColor = onStart;
                        envForm.Location = tempLocation;
                    }
                    else if (btnList.BackColor == onMain)
                    {
                        btnList.BackColor = onStart;
                        listForm.Location = tempLocation;
                    }
                    else if (btnTemp.BackColor == onMain)
                    {
                        btnTemp.BackColor = onStart;
                        tempForm.Location = tempLocation;
                    }
                    else if (btnErp.BackColor == onMain)
                    {
                        btnErp.BackColor = onStart;
                        erpForm.Location = tempLocation;
                    }
                    btnOper.BackColor = onMain;
                    operForm.Location = mainLocation;
                    FormMax();
                }

            }

        }

        private void button5_Click(object sender, EventArgs e)
        {
            label6.Text = "当前位置：X=" + envForm.Location.X + ",Y=" + envForm.Location.Y;
            label7.Text = "当前位置：X=" + tempForm.Location.X + ",Y=" + tempForm.Location.Y;
            label8.Text = "当前位置：X=" + listForm.Location.X + ",Y=" + listForm.Location.Y;
            label9.Text = "当前位置：X=" + operForm.Location.X + ",Y=" + operForm.Location.Y;
            label10.Text = "当前位置：X=" + erpForm.Location.X + ",Y=" + erpForm.Location.Y;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            listForm.Location = new Point(0,0);
            envForm.Location = new Point(0, 0);
            tempForm.Location = new Point(0, 0);
            operForm.Location = new Point(0, 0);
            erpForm.Location = new Point(0, 0);

        }

        private void btnErp_MouseUp(object sender, MouseEventArgs e)
        {
            FormMin();
            Point tempLocation = erpForm.Location;
            if (e.Button == MouseButtons.Right)//选中env软件
            {
                if (btnErp.BackColor == onStart)
                {
                    if (btnEnv.BackColor == onMain)
                    {
                        btnEnv.BackColor = onStart;
                        envForm.Location = tempLocation;
                    }
                    else if (btnList.BackColor == onMain)
                    {
                        btnList.BackColor = onStart;
                        listForm.Location = tempLocation;
                    }
                    else if (btnTemp.BackColor == onMain)
                    {
                        btnTemp.BackColor = onStart;
                        tempForm.Location = tempLocation;
                    }
                    else if (btnOper.BackColor == onMain)
                    {
                        btnOper.BackColor = onStart;
                        operForm.Location = tempLocation;
                    }
                    btnErp.BackColor = onMain;
                    erpForm.Location = mainLocation;
                    FormMax();
                }

            }
            
        }
        private void FormMax()
        {
            listForm.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            envForm.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            tempForm.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            operForm.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            erpForm.WindowState = System.Windows.Forms.FormWindowState.Maximized;
        }
        private void FormMin()
        {
            listForm.WindowState = System.Windows.Forms.FormWindowState.Normal;
            envForm.WindowState = System.Windows.Forms.FormWindowState.Normal;
            tempForm.WindowState = System.Windows.Forms.FormWindowState.Normal;
            operForm.WindowState = System.Windows.Forms.FormWindowState.Normal;
            erpForm.WindowState = System.Windows.Forms.FormWindowState.Normal;
        }
    }
}
